# 查看两个文件的课程，将老师和学生成绩关联到一起，并写入到新的文件中去
course_teacher_map = {}
with open("019.txt", "r", encoding="utf-8") as tfile:
    for line in tfile:
        line = line[:-1]
        course, teacher = line.split(",")
        course_teacher_map[course] = teacher
    print(course_teacher_map)

final_str = ""
with open("018.txt", "r+", encoding="utf-8") as stufile:
    for line in stufile:
        line = line[:-1]
        course, sno, name, score = line.split(",")
        teacher = course_teacher_map.get(course)
        print(teacher)
        print(line)
        result_str = line + "," + f"{teacher}"
        print(result_str)
        with open("019result.txt", "a+", encoding="utf-8") as refile:
            result_str = result_str + "\n"
            refile.write(result_str)


